package com.smart.campus.web.controller.common;


import org.springframework.http.HttpStatus;

public class JsonResultExt {

	private int code;
	private String message;
	private Object data;

	public JsonResultExt() {
		this.setCode(HttpStatus.OK.value());
		this.setMessage(HttpStatus.OK.name());

	}

	public JsonResultExt(HttpStatus httpStatus) {
		this.setCode(httpStatus.value());
		this.setMessage(httpStatus.name());
	}

	public JsonResultExt(int code, String message) {
		this.setCode(code);
		this.setMessage(message);
	}

	public JsonResultExt(int code, String message, Object data) {
		this.setCode(code);
		this.setMessage(message);
		this.setData(data);
	}
	
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}



	public void run(JsonResultExt jsonResult , Object obj) {
		try {
			jsonResult.setData(obj);
			jsonResult.setCode(HttpStatus.OK.value());
			jsonResult.setMessage(HttpStatus.OK.name());
		} catch (Exception e) {
			jsonResult.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
			jsonResult.setMessage(HttpStatus.INTERNAL_SERVER_ERROR.name());
			e.printStackTrace();
		}
	}
}
